<?php

namespace Plu\Library\Services\Platform\Admire;

use  Plu\Library\Services\ServiceBase,
     Plu\Library\Models\Platform\Admire\Admire,
     Plu\Library\Services\Redis\Admire\AdmireRedis;

class AdmireService extends ServiceBase{
    /**
     * @param $type
     * 更新redis数据到数据库中
     */
    public function updateAdmireCountsTask($type) {
        $admireRedis = new AdmireRedis();
        $admire = new Admire();
        $date = strtotime('-1 day');
        $hash_key = sprintf($admireRedis::key_of_admire_day,$type,date('ymd',$date));

        foreach($admireRedis->getAdmireByType($hash_key,false) as $item) {
            foreach ($item as $guid => $count) {
                $admire->updateItemCount($type, $guid, $count);
            }
        }
    }
}
?>
